package com.dz.core.dto;


import com.dz.core.constant.ResCode;

public class ResBody {

    private int status;
    private String message;
    private Object result;


    public ResBody() {
    }

    public ResBody(ResCode code) {
        this.status = code.getKey();
        this.message = code.getValue();
    }

    public ResBody(ResCode code, Object result) {
        this.status = code.getKey();
        this.message = code.getValue();
        this.result = result;
    }

    public ResBody(ResCode code, String message,Object result) {
        this.status = code.getKey();
        this.message = message;
        this.result = result;
    }

    /**
     * 构建Response成功响应数据
     * @param result
     * @return
     */
    public static ResBody generate(BusResult result){
        ResBody resBody = new ResBody();
        resBody.build(result,ResCode.SUCCESS);
        return resBody;
    }



    /**
     * 构建业务响应数据
     * @param result
     * @param resCode
     * @return
     */
    private void build(BusResult result,ResCode resCode){
        this.setStatus(resCode.getKey());
        this.setMessage(resCode.getValue());
        this.setResult(result);
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getResult() {
        return result;
    }

    public void setResult(Object result) {
        this.result = result;
    }
}
